package cn.zw.design.decorator;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
 *   装饰模式   对字节流进行装饰 
 * @author Administrator
 *
 */
public class LowerCaseInputStream extends FilterInputStream {

	protected LowerCaseInputStream(InputStream in) {
		super(in);
	}

	@Override
	public int read() throws IOException {
		int c = super.read();
		return (c == -1 ? c : Character.toLowerCase((char)c));//表明一个一个的字节的读
	}
	
	public int  read(byte[] b,int offset,int len)  throws IOException{
		int result = super.read(b, offset, len);
		for (int i = offset; i < offset+result; i++) {
		b[i] = (byte)Character.toLowerCase((char)b[i]);
		}
		return result;
	}
	

	public static void main(String[] args) {
		
		
		try {
			InputStream is = new LowerCaseInputStream(new FileInputStream("d:\\asdf.txt"));
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String  line = null;
			while(  null!= (line = br.readLine())){
				System.out.println(line);
			}
			br.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	
	
}
